package com.ojoin.trade.t0loan_core.web.dao.impl;

import java.util.HashMap;
import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import com.ojoin.trade.common.exception.BusinessException;
import com.ojoin.trade.common.exception.DaoException;
import com.ojoin.trade.common.web.dao.impl.BaseDaoImpl;
import com.ojoin.trade.common_core.web.dao.TbTransferTokenStatusDao;
import com.ojoin.trade.common_core.web.domain.TbTransferTokenStatus;
import com.ojoin.trade.common_core.web.domain.TransferErrorStatusInfo;

@Repository
public class TbTransferTokenStatusDaoImpl extends BaseDaoImpl<TbTransferTokenStatus> implements TbTransferTokenStatusDao {
	
	public SqlSession getSqlSession() {
		return this.sqlSessionTemplate;
	}

	@Override
	public int updateTransferTokenStatus(String token, int transstatus,String msg)
			throws BusinessException {
		String mapMethodName = "updateTransferTokenStatus";
		try {
			HashMap<String, Object> paramMap = new HashMap<String, Object>();
			paramMap.put("token", token);
			paramMap.put("transstatus", transstatus);
			paramMap.put("returnmsg",msg);
			return getSqlSession().update(getSqlName(mapMethodName), paramMap);
		} catch (Exception e) {
			throw new DaoException(String.format("更新转账操作状态对象出错！语句：%s",
					getSqlName(mapMethodName)), e);
		}
	}

	@Override
	public List<TransferErrorStatusInfo> queryDoingTransferList(Pageable page)
			throws BusinessException {
		String mapMethodName = "queryErrorTransferList";
		try {
			return getSqlSession().selectList(getSqlName(mapMethodName), this.getPageBounds(page));
		} catch (Exception e) {
			throw new DaoException(String.format("查询异常转账操作列表出错！语句：%s",
					getSqlName(mapMethodName)), e);
		}
	}

    @Override
    public TransferErrorStatusInfo queryByToken(String token) throws BusinessException {
        String mapMethodName = "queryByOrderid";
        try {
            return getSqlSession().selectOne(getSqlName(mapMethodName), token);
        } catch (Exception e) {
            throw new DaoException(String.format("查询转账放款方电话出错！语句：%s",
                    getSqlName(mapMethodName)), e);
        }
    }

}
